import { defineStore } from "pinia";
import { reactive } from "vue";
import { Position } from "../composables/usePosition";

interface Target {
    x:number
    y:number
}

export const useTargetStore = defineStore('targetStore',() => {
    const targets = reactive<Target[]>([])
    function createTarget({x,y}:{x:number,y:number}):Target {
        return {
            x,
            y
        }
    }
    function addTarget(target:Target) {
        targets.push(target)
    }

    function findTarget(position:Position) {
        return targets.find(target => target.x === position.x && target.y === position.y)
    }

    function cleanAllTargets() {
        targets.splice(0,targets.length)
    }

    return {
        targets,
        createTarget,
        addTarget,
        findTarget,
        cleanAllTargets
    }
})